﻿using Flurl.Http;
using OkFlurl;
using System;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {

        FlurlProgress progress;

        public Form1()
        {
            InitializeComponent();

            progress = new FlurlProgress(data =>
            {
                //Console.WriteLine($"文件大小:{total},当前已下载:{downloadLen}");
                //Console.WriteLine("\r%{0:N4}", percent * 100);

                label1.Text = (data.Percent * 100).ToString();

                progressBar1.Value = Convert.ToInt32(data.Percent * 100);

            });

            //progress.Init(true);
        }



        private async void button1_Click(object sender, EventArgs e)
        {
            var url = "https://pics0.baidu.com/feed/f603918fa0ec08fa82fd8b393277786057fbdad2.jpeg?token=a4ad50eb633955c5da143b63f685e4c7";
            //url = "http://download.osgeo.org/postgis/windows/pg16/postgis-bundle-pg16x64-setup-3.4.1-1.exe";
            //url = "http://localhost:5212/test/down";
            var req = new FlurlRequest(url);
            await FlurlExt.GetDownloadDiskAsync(req, null, @"C:\\A", null, progress, 10);

            progress.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            progress.Stop();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            progress.Start();

        }
    }
}
